<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>客户管理</title>
    <% include("/common/common_css_js.html"){} %>
</head>
<body>
    <div style="padding-bottom: 5px;">
        <div id="queryForm" class="uc-toolbaroverflow" _borderStyle="border-top:0;">
            <span>客户信息：</span>
            <input id="keyName" name="keyName" style="width: 300px" class="mini-textbox" emptyText="客户名称或客户电话" />
            <span>归属部门：</span>
            <input id="keyDepartmentId" name="keyDepartmentId" class="mini-treeselect" style="width: 250px;" textField="name" valueField="id" emptyText="请选择..."
                   expandOnLoad="2"  virtualScroll="true"  required="false" allowInput="true" showNullItem="true" nullItemText="请选择..." />
            <span>业务员：</span>
            <input id="keySalesmanId" name="keySalesmanId" class="mini-combobox" style="width: 250px;" textField="name" valueField="id" emptyText="请选择..."
                   required="false" allowInput="true" showNullItem="true" nullItemText="请选择..." />

            <div style="margin-top: 5px"></div>
            <% if(so.hasPermission("bCustomer:query")){%>
                <a class="mini-button" iconCls="icon-search" onclick="search()">查询</a>
            <% } %>

            <% if(so.hasPermission("bCustomer:queryCndClear")){%>
                <a class="mini-button" iconCls="icon-new" onclick="clearSearch()">清空查询条件</a>
            <% } %>

            <span class="separator"></span>

            <% if(so.hasPermission("bCustomer:add")){%>
                <a class="mini-button" iconCls="icon-add" onclick="add()">新增</a>
            <% } %>

            <% if(so.hasPermission("bCustomer:edit")){%>
                <a class="mini-button" iconCls="icon-edit" onclick="update()">编辑</a>
            <% } %>

            <% if(so.hasPermission("bCustomer:delete")){%>
                <a class="mini-button" iconCls="icon-remove" onclick="deleteCustomer()">删除</a>
            <% } %>

            <span class="separator"></span>

            <% if(so.hasPermission("bCustomer:download")){%>
                <#download_grid id="downloadGrid" theGridId="datagrid1" theFileName="客户列表"/>
            <% } %>

        </div>
    </div>

    <div class = "mini-fit">
        <div id="datagrid1" class="mini-datagrid"
             style="width: 100%; height: 100%;"
             url="${base}/pages/customer_manage/query" idField="id"
             showPager="true" pageSize="20" sizeList="[10,20,30,50,100]"
             allowResize="true"
             allowCellWrap="false">
            <div property="columns">
<!--                <div field="id" width="0" headerAlign="center" align="left" allowSort="true">表ID</div>-->
                <div field="name" width="140" headerAlign="center" align="left" allowSort="true">客户名称</div>
                <div field="address" width="140" headerAlign="center" align="left" allowSort="true">客户地址</div>
                <div field="phone" width="140" headerAlign="center" align="center" allowSort="true" renderer="commonDesensitization">客户电话</div>
                <div field="departmentId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"department"}' renderer="commonRender">归属部门</div>
                <div field="salesmanId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysUser"}' renderer="commonRender">业务员</div>
                <div width="140" headerAlign="center" align="center" allowSort="true" renderer="phoneRender">业务员电话</div>
                <div field="supportMonthlyStatementStatusId" width="105" headerAlign="center" align="center" allowSort="true"  data-options='{cacheName:"sysDic"}' renderer="commonRender">支持欠款(月结)</div>
                <div field="airFreightInsuranceRate" width="140" headerAlign="center" align="center" allowSort="true">空运保险费率</div>
                <div field="autoInsuranceRate" width="140" headerAlign="center" align="center" allowSort="true">汽运保险费率</div>
                <div field="arrearsLines" width="80" headerAlign="center" align="center" allowSort="true">欠费额度</div>
                <div field="creditTerm" width="100" headerAlign="center" align="center" allowSort="true">信用期限（天）</div>
                <div field="comment" width="140" headerAlign="center" align="center" allowSort="true">备注</div>
            </div>
        </div>
    </div>

    <!--编辑窗口-->
    <div id="updatePanel" class="mini-window" title="客户管理" style="width:1200px;height:700px;"
         showMaxButton="true" showCollapseButton="false" showMinButton="true" showShadow="true"
         showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true">
        <div property="footer" style="padding:10px;text-align: right">
            <a  id="insertOrUpdateSaveBtn" name="insertOrUpdateSaveBtn" class="mini-button" iconCls="icon-save" onclick="saveInsertOrUpdate()">保存</a>
            <a  class="mini-button" iconCls="icon-close" onclick="public_onCancel('updatePanel')">关闭</a>
        </div>
        <div id="customerForm">
            <input id="id" name="id"  class="mini-hidden"  emptyText="无需填写" />

            <span>客户名称:</span>
            <input  id="name" name="name"  class="mini-textbox" required="true" style="width:40%" requiredErrorText="名称不能为空"/>

            <span>客户电话:</span>
            <input id="phone" name="phone"  class="mini-textbox" required="true" requiredErrorText="客户电话不能为空" style="width:20%;"/>

            <div style="margin-top: 5px"></div>
            <span>客户地址:</span>
            <input id="address" name="address"  class="mini-textbox" required="true" requiredErrorText="客户地址不能为空" style="width:40%;"/>

            <span>备注:</span>
            <input id="comment" name="comment" class="mini-textbox" required="false" requiredErrorText="客户备注不能为空" style="width:40%;"/>

            <div style="margin-top: 5px"></div>
            <span>归属部门:</span>
            <input id="departmentId" name="departmentId" class="mini-treeselect" style="width: 250px;" textField="name" valueField="id" emptyText="请选择..."
                   expandOnLoad="2"  virtualScroll="true" required="true" allowInput="true" showNullItem="true" nullItemText="请选择..." requiredErrorText="归属部门不能为空" />

            <span>业务员:</span>
            <input id="salesmanId" name="salesmanId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                   required="true" allowInput="true" showNullItem="true" nullItemText="请选择..." requiredErrorText="业务员不能为空"/>

            <span>支持欠款月结:</span>
            <input id="supportMonthlyStatementStatusId" name="supportMonthlyStatementStatusId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                   required="true" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="支持欠款月结不能为空"/>

            <div style="margin-top: 5px"></div>
            <span>信用期限(天):</span>
            <input id="creditTerm" name="creditTerm" class="mini-textbox" vtype="float"  value="0"  required="true" requiredErrorText="信用期限不能为空" />

            <span>欠费额度:</span>
            <input id="arrearsLines" name="arrearsLines"  class="mini-textbox" vtype="float"  value="0" required="true" requiredErrorText="欠费额度不能为空" />

            <span>空运保险费率:</span>
            <input id="airFreightInsuranceRate" name="airFreightInsuranceRate" class="mini-textbox" vtype="float"  value="0" required="true" requiredErrorText="空运保险费率不能为空" />

            <span>汽运保险费率:</span>
            <input id="autoInsuranceRate" name="autoInsuranceRate"  class="mini-textbox" vtype="float"  value="0" required="true" requiredErrorText="汽运保险费率不能为空" />


            <div style="margin-top: 5px"></div>
            <span>客户联系人</span>
            <div style="margin-top: 5px"></div>
            <input id="contactName" name="contactName" class="mini-textbox" emptyText="联系人姓名"/>
            <input id="contactPhone" name="contactPhone" class="mini-textbox" emptyText="联系人电话"/>
            <input id="contactComment" name="contactComment" class="mini-textbox" emptyText="说明"/>
            <a class="mini-button" iconCls="icon-add" onclick="addContactToDatagrid()">添加</a>
            <a class="mini-button" iconCls="icon-remove" onclick="removeContactFromDatagrid()">剔除</a>
            <div style="margin-top: 5px"></div>
            <div id="contactDatagrid" class="mini-datagrid"
                 style="width: 100%; height: 150px;" idField="id"
                 multiSelect = "true"
                 showPager="false"  allowResize="true">
                <div property="columns">
                    <div type="checkcolumn" ></div>
                    <div field="name" width="80" headerAlign="center" align="center">姓名</div>
                    <div field="phone" width="80" headerAlign="center" align="center">电话</div>
                    <div field="comment" width="90" headerAlign="center" align="left">说明</div>
                </div>
            </div>


            <div style="margin-top: 5px"></div>
            <span>客户发票信息<span style="color: blue;margin-left: 5px">注：添加发票抬头时会以<span style="color: red">【纳税人识别号】</span>做为唯一标识去重复</span></span>
            <div style="margin-top: 5px"></div>

            <input id="invoiceTitle" name="invoiceTitle" class="mini-textbox" emptyText="发票抬头" style="width: 300px"/>
            <input id="taxpayerIdentificationNumber" name="taxpayerIdentificationNumber" class="mini-textbox" emptyText="纳税人识别号" style="width: 300px"/>
            <input id="phoneNumber" name="phoneNumber" class="mini-textbox" emptyText="电话号码"/>
            <input id="invoiceAddress" name="invoiceAddress" class="mini-textbox" emptyText="地址" style="width: 300px"/>
            <div style="margin-top: 5px"></div>
            <input id="openAccountBankId" name="openAccountBankId" class="mini-combobox"  textField="name" valueField="id" emptyText="请选择开户银行..."
                   style="width: 300px"  required="false" allowInput="true" showNullItem="true" nullItemText="开户银行..." requiredErrorText="开户银行"/>
            <input id="bankAccount" name="bankAccount" class="mini-textbox" emptyText="银行账号" style="width: 300px" />
            <input id="invoiceTypeId" name="invoiceTypeId" class="mini-combobox" style="width:180px;" textField="name" valueField="id" emptyText="请选择发票类型..."
                    required="false" allowInput="true" showNullItem="true" nullItemText="发票类型..." requiredErrorText="没有选择发票类型"/>
            <input id="rateId" name="rateId" class="mini-combobox" style="width:180px;" textField="name" valueField="id" emptyText="请选择税率..."
                   required="false" allowInput="true" showNullItem="true" nullItemText="税率..." requiredErrorText="没有选择税率"/>
            <div style="margin-top: 5px"></div>
            <input id="recipientName" name="recipientName" emptyText="收件人" style="width: 200px"  class="mini-textbox" required="false" requiredErrorText="收件人不能为空" />
            <input id="recipientPhone" name="recipientPhone" emptyText="收件人电话" style="width: 200px"  class="mini-textbox" required="false" requiredErrorText="收件人电话不能为空" />
            <input id="recipientAddress" name="recipientAddress" emptyText="收件人地址" style="width: 300px"  class="mini-textbox" required="false" requiredErrorText="收件人地址不能为空" />

            <a class="mini-button" iconCls="icon-add" onclick="addInvoiceDatagrid()">添加</a>
            <a class="mini-button" iconCls="icon-remove" onclick="removeInvoiceDatagrid()">剔除</a>

            <div style="margin-top: 5px"></div>
            <div id="invoiceDatagrid" class="mini-datagrid"
                 style="width: 100%; height: 150px;" idField="id"
                 multiSelect = "true"
                 showPager="false"  allowResize="true">
                <div property="columns">
                    <div type="checkcolumn" ></div>
                    <div field="invoiceTitle" width="120" headerAlign="center" align="left">发票抬头</div>
                    <div field="taxpayerIdentificationNumber" width="100" headerAlign="center" align="center">纳税人识别号</div>
                    <div field="phoneNumber" width="80" headerAlign="center" align="center">电话号码</div>
                    <div field="invoiceAddress" width="80" headerAlign="center" align="center">地址</div>
                    <div field="openAccountBankId" width="80" headerAlign="center" align="center" data-options='{cacheName:"bank"}' renderer="commonRender">开户银行</div>
                    <div field="bankAccount" width="80" headerAlign="center" align="center">银行账号</div>
                    <div field="invoiceTypeId" width="60" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">发票类型</div>
                    <div field="rateId" width="60" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">税率</div>
                    <div field="recipientName" width="80" headerAlign="center" align="center">收件人</div>
                    <div field="recipientPhone" width="80" headerAlign="center" align="center">收件人电话</div>
                    <div field="recipientAddress" width="80" headerAlign="center" align="center">收件人地址</div>
                </div>
            </div>


        </div>
    </div>
    <script type="text/javascript">
        mini.parse();
        let grid = mini.get("datagrid1");
        let oper;
        let customerForm = new mini.Form("#customerForm");

        // 联系人 grid   contactName  contactPhone  contactComment  contactDatagrid
        let contactName = mini.get("contactName");
        let contactPhone = mini.get("contactPhone");
        let contactComment = mini.get("contactComment");
        let contactDatagrid = mini.get("contactDatagrid");


        // 发票 grid
        let invoiceTitle = mini.get("invoiceTitle");
        let taxpayerIdentificationNumber = mini.get("taxpayerIdentificationNumber");
        let phoneNumber = mini.get("phoneNumber");
        let invoiceAddress = mini.get("invoiceAddress");
        let openAccountBankId = mini.get("openAccountBankId");
        let bankAccount = mini.get("bankAccount");
        let invoiceTypeId = mini.get("invoiceTypeId");
        let rateId = mini.get("rateId");
        let recipientName = mini.get("recipientName");
        let recipientPhone = mini.get("recipientPhone");
        let recipientAddress = mini.get("recipientAddress");

        let invoiceDatagrid = mini.get("invoiceDatagrid");

        // 客户联系人数组
        let contactArray = [];
        //  客户发票数组
        let invoiceArray = [];

        $(function () {
            // 加载列表数据
            grid.load();

            //新增、修改弹出框默认操作
            oper = OPER_ADD();

            let departmentJsonData = commonRenderDropList("department");
            mini.get("keyDepartmentId").loadList(departmentJsonData, "id", "pid");
            mini.get("departmentId").loadList(public_deepClone(departmentJsonData), "id", "pid");

            // keyName  keyContactName  keyDepartmentId  keySalesmanId
            let salesmanJsonData = commonRenderDropList("sysUser");
            mini.get("keySalesmanId").load(salesmanJsonData);
            mini.get("salesmanId").load(public_deepClone(salesmanJsonData));

            let supportMonthlyStatementStatusIdJsonData = commonRenderSysDicDropListByKey("sysDic", "XT_DIC_YES_NO");
            mini.get("supportMonthlyStatementStatusId").load(supportMonthlyStatementStatusIdJsonData);

            let invoiceTypeIdJsonData = commonRenderSysDicDropListByKey("sysDic", "XT_DIC_INVOICE_TYPE");
            invoiceTypeId.load(invoiceTypeIdJsonData);

            let rateIdJsonData = commonRenderSysDicDropListByKey("sysDic", "XT_DIC_INVOICE_RATE");
            rateId.load(rateIdJsonData);


        });

        function search() {
            let form = new mini.Form("#queryForm");
            let data = form.getData(true);
            grid.load(data);
        }

        function clearSearch() {
            let form = new mini.Form("#queryForm");
            form.clear();
        }

        // 清空两个 datagrid 及相应数组
        function emptyArray(){
            contactArray.splice(0,contactArray.length);
            invoiceArray.splice(0,invoiceArray.length);

            contactDatagrid.clearRows();
            invoiceDatagrid.clearRows();

        }

        function add(){
            emptyArray();
            customerForm.clear();
            mini.get("creditTerm").setValue(0);
            mini.get("arrearsLines").setValue(0);
            mini.get("airFreightInsuranceRate").setValue(0);
            mini.get("autoInsuranceRate").setValue(0);

            let openAccountBankIdJsonData =commonRenderDropList("bank");
            openAccountBankId.load(openAccountBankIdJsonData);

            oper = OPER_ADD();
            // 弹出添加窗口
            public_showModelAtPos("updatePanel", "center", "middle");

        }

        function update(){
            emptyArray();
            customerForm.clear();
            // 获取当前选中的行
            let selectedItem = grid.getSelected();
            if(!selectedItem){
                showAlert("请选择要编辑的行!");
                return;
            }

            oper = OPER_UPDATE();

            customerForm.setData(selectedItem);

            // 根据客户 id 加载相应的信息客户联系人
            let retContactArray = public_getServerData("${base}/pages/customer_manage/contact/queryContactByCustomerId",{customerId:selectedItem.id});
            if(!public_isEmpty(retContactArray) && retContactArray.length>0){
                contactArray.splice(0,contactArray.length,...retContactArray);
                reBindContactDatagrid();
            }

            // 根据客户 id 加载客户发票抬头信息
            let retInvoiceArray = public_getServerData("${base}/pages/customer_manage/invoice/queryInvoiceByCustomerId",{customerId:selectedItem.id});
            if(!public_isEmpty(retInvoiceArray) && retInvoiceArray.length>0){
                invoiceArray.splice(0,invoiceArray.length,...retInvoiceArray);
                reBindInvoiceDatagrid()
            }

            let openAccountBankIdJsonData =commonRenderDropList("bank");
            openAccountBankId.load(openAccountBankIdJsonData);

            // 弹出添加窗口
            public_showModelAtPos("updatePanel", "center", "middle");

        }

        //新增保存或修改保存
        function saveInsertOrUpdate(){
            // 添加并保存
            customerForm.validate();
            if (customerForm.isValid() == false){
                public_showErrorTips("请将信息填写完整再进行下一步！");
                return;
            }
            let data = customerForm.getData(true);
            data.fullPinyin = pinyin.getFullChars(data.name);
            data.camelCharPinyin = pinyin.getCamelChars(data.name);
            data.shortName = data.name;
            data.shortNameFullPinyin = data.fullPinyin;
            data.shortNameCamelCharPinyin = data.camelCharPinyin;

            if(contactArray.length==0){
                showAlert("客户没有添加联系人，不能保存!");
                return;
            }

            mini.confirm(
                "确定保存客户信息?",
                "客户保存",
                function(action) {
                    if (action == "ok") {
                        let methodName = oper == OPER_ADD() ? "insert" : "update";
                        let ret = public_getServerData("${base}/pages/customer_manage/" + methodName, {customerPojo:data, contactPojoList:contactArray, invoicePojoList:invoiceArray});
                        showAlert(ret.message,function (){
                            if(ret.ok) {
                                // 重新刷新数据
                                grid.reload();
                                public_onCancel('updatePanel');
                                refreashCache();

                            }
                        });
                    }
                });
        }

        function phoneRender(e) {
            let record = e.record;
            let user = commonRendderObjByKeyAndId("sysUser",record.salesmanId);
            if(public_isEmpty(user)){
                return "";
            }
            // 电话号码要进行脱敏处理
            return desensitization(user.mobile);
        }

        function deleteCustomer(){
            let select = grid.getSelected();
            if(select == null){
                public_showErrorTips("未选中");
                return;
            }
            mini.confirm(
                "确定删除选择的客户？",
                "确定提示",
                function(action) {
                    if (action == "ok") {
                        let ret = public_getServerData("${base}/pages/customer_manage/delete",select.id);
                        showAlert(ret.message,function (){
                            if(ret.ok){
                                // 重新刷新数据
                                grid.removeRow(select, true);
                                refreashCache();
                            }
                        });
                    }
                });
        }

        /**
         * 添加联系人到 grid
         * contactName  contactPhone  contactComment
         */
        function addContactToDatagrid(){
            let idValue = mini.get("id").getValue();
            let contactNameValue = contactName.getValue().trim();
            let contactPhoneValue = contactPhone.getValue().trim();
            let contactCommentValue = contactComment.getValue().trim();

            if(contactNameValue.length==0 || contactPhoneValue.length==0){
                showAlert("没有填写联系人姓名或电话，不能添加联系人信息!");
                return;
            }

            // 定义对象  fullPinyin  camelCharPinyin
            let contactObj = {customerId:idValue, name:contactNameValue,phone:contactPhoneValue,comment:contactCommentValue, fullPinyin:pinyin.getFullChars(contactNameValue), camelCharPinyin:pinyin.getCamelChars(contactNameValue)};
            // 检测是否有重复，根据 name与 phone
            let isExist = false;
            for(let obj of contactArray){
                if(obj.name == contactObj.name && obj.phone == contactObj.phone){
                    isExist = true;
                }
            }

            if(isExist){
                showAlert("联系人【" + contactNameValue + "】电话【" + contactPhoneValue + "】已经存在,不能重复添加!");
                return;
            }
            // 加入数组
            contactArray.push(contactObj);

            reBindContactDatagrid();
        }

        function reBindContactDatagrid(){
            // 清空表格
            contactDatagrid.clearRows();

            // 重新绑定数据
            for(let obj of contactArray){
                contactDatagrid.addRow(obj);
            }
        }

        /**
         * 移除联系人从 grid
         */
        function removeContactFromDatagrid(){
            let selectedItems = contactDatagrid.getSelecteds();
            if(selectedItems.length==0){
                showAlert("没有选择需要剔除的联系人对象!");
                return;
            }

            // 这是编辑，则需要检测是否已经使用过，如果没有使用过可以进行删除，否则不能剔除
            for(let selectObj of selectedItems){
                if(!public_isEmpty(selectObj.customerId)){
                    let ret = public_getServerData("${base}/pages/customer_manage/contact/checkUsed",selectObj);
                    if(ret.ok){
                        showAlert("联系人【" + selectObj.name + "】使用中，不能剔除!");
                        return;
                    }
                }
            }

            // 这是添加新客户或通过检测可以直接删除
            let tempContactArray = [];
            for(let obj of contactArray){
                let flag = false;
                for(let selectObj of selectedItems){
                    if(obj.name==selectObj.name && obj.phone == selectObj.phone){
                        flag = true;
                        break;
                    }
                }
                if(!flag){
                    tempContactArray.push(obj);
                }
            }
            contactArray.splice(0,contactArray.length,...tempContactArray);
            // 重新绑定
            reBindContactDatagrid();
        }



        /**
         * 添加发票信息到 grid
         *  let invoiceTitle = mini.get("invoiceTitle");
         let taxpayerIdentificationNumber = mini.get("taxpayerIdentificationNumber");
         let phoneNumber = mini.get("phoneNumber");
         let address = mini.get("address");
         let openAccountBankId = mini.get("openAccountBankId");
         let bankAccount = mini.get("bankAccount");
         let invoiceTypeId = mini.get("invoiceTypeId");
         let rateId = mini.get("rateId");
         let invoiceDatagrid = mini.get("invoiceDatagrid");
          */
        function addInvoiceDatagrid(){
            let idValue = mini.get("id").getValue();
            let invoiceTitleValue = invoiceTitle.getValue().trim();
            let taxpayerIdentificationNumberValue = taxpayerIdentificationNumber.getValue().trim();
            let phoneNumberValue = phoneNumber.getValue().trim();
            let invoiceAddressValue = invoiceAddress.getValue().trim();
            let openAccountBankIdValue = openAccountBankId.getValue().trim();
            let bankAccountValue = bankAccount.getValue().trim();
            let invoiceTypeIdValue = invoiceTypeId.getValue().trim();
            let rateIdValue = rateId.getValue().trim();
            let recipientNameValue = recipientName.getValue().trim();
            let recipientPhoneValue = recipientPhone.getValue().trim();
            let recipientAddressValue = recipientAddress.getValue().trim();


            if(isEmpty(invoiceTitle,"发票抬头")){
                return;
            }

            if(isEmpty(taxpayerIdentificationNumber,"纳税人识别号")){
                return;
            }

            if(isEmpty(phoneNumber,"纳税人电话")){
                return;
            }

            if(isEmpty(openAccountBankId,"纳税人开户银行")){
                return;
            }

            if(isEmpty(bankAccount,"纳税人银行账号")){
                return;
            }

            if(isEmpty(invoiceTypeId,"发票类型")){
                return;
            }

            if(isEmpty(rateId,"开票税率")){
                return;
            }

            // 构建对象
            let invoiceObj = {customerId:idValue, invoiceTitle:invoiceTitleValue, taxpayerIdentificationNumber:taxpayerIdentificationNumberValue,
                phoneNumber:phoneNumberValue, invoiceAddress:invoiceAddressValue, openAccountBankId:openAccountBankIdValue,
                bankAccount:bankAccountValue, invoiceTypeId:invoiceTypeIdValue, rateId:rateIdValue,
                recipientName:recipientNameValue, recipientPhone:recipientPhoneValue, recipientAddress:recipientAddressValue
            };

            let isExist = false;
            for(let obj of invoiceArray){
                if(obj.taxpayerIdentificationNumber == invoiceObj.taxpayerIdentificationNumber){
                    isExist = true;
                    break;
                }
            }
            if(isExist){
                showAlert("待添加的开票信息已经存，不能重复添加!");
                return;
            }

            invoiceArray.push(invoiceObj);
            reBindInvoiceDatagrid();
        }

        // 重新绑定数据
        function reBindInvoiceDatagrid(){
            // 清空表格
            invoiceDatagrid.clearRows();

            // 重新绑定数据
            for(let obj of invoiceArray){
                invoiceDatagrid.addRow(obj);
            }
        }

        /**
         * 移除发票信息到 grid
         */
        function removeInvoiceDatagrid(){
            let selectedItems = invoiceDatagrid.getSelecteds();
            if(selectedItems.length==0){
                showAlert("没有选择需要剔除的开票信息对象!");
                return;
            }

            let idValue = mini.get("id").getValue();
            if(idValue.length!=0){
                // 这是编辑，则需要检测是否已经使用过，如果没有使用过可以进行删除，否则不能剔除
                for(let selectObj of selectedItems){

                }
            }

            // 这是添加新客户或通过检测时可以直接删除
            let tempInvoiceArray = [];
            for(let obj of invoiceArray){
                let flag = false;
                for(let selectObj of selectedItems){
                    if(obj.taxpayerIdentificationNumber==selectObj.taxpayerIdentificationNumber && obj.taxpayerIdentificationNumber == selectObj.taxpayerIdentificationNumber){
                        flag = true;
                        break;
                    }
                }
                if(!flag){
                    tempInvoiceArray.push(obj);
                }
            }
            invoiceArray.splice(0,invoiceArray.length,...tempInvoiceArray);
            // 重新绑定
            reBindInvoiceDatagrid();
        }

        // 刷新缓存，把刷新的缓存放到父页面，应当调用父级页面方法刷新
        function refreashCache() {
            parent.window.loadCache();
        }

    </script>
</body>
</html>